#!/usr/bin/env expect
# Author: Jordan Rupprecht
# USAGE - sendkey.sh USER HOST PASSWORD KEYCONTENTS
# e.g. sendkey.sh jordan clic.cs.columbia.edu passw0rd `cat id_rsa.pub`

spawn ssh -q -l [lindex $argv 0] [lindex $argv 1] "mkdir -p ~/.ssh &>/dev/null; chmod 700 ~/.ssh; echo \"[lrange $argv 3 5]\" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys"
expect *word:
send "[lindex $argv 2]\n"
expect
